<template xmlns='http://www.w3.org/1999/html'>
  <!--  <a-modal-->
  <!--    :title="'核销申请'"-->
  <!--    width='100%'-->
  <!--    :visible='true'-->
  <!--    :confirmLoading='confirmLoading'-->
  <!--    switchFullscreen-->
  <!--    style='height: 100%;overflow: auto;padding-bottom: 53px;'>-->
  <!--        <template slot='footer'>-->
  <!--    &lt;!&ndash;      <a-button @click='handleCancel'>取消</a-button>&ndash;&gt;-->
  <!--          <a-button @click='browerGo' type='primary'  :disabled='disableSubmit' :loading='confirmLoading'>返回</a-button>-->
  <!--    &lt;!&ndash;      <a-button @click='handleOk("2")' type='primary'  :disabled='disableSubmit' :loading='confirmLoading'>保存并提交</a-button>&ndash;&gt;-->
  <!--        </template>-->
  <div  style='padding: 11px'>
    <a-spin :spinning='confirmLoading'>
      <a-form :form='form'>
        <a-row :gutter='24'>
          <a-col :md='24' :sm='24' style=' border-bottom: 1px solid #cdcdcd;margin-bottom: 12px'>
            <span class='activeMess'>活动信息</span>
          </a-col>
          <a-col :md='8' :sm='24'>
            <a-form-item label='活动名称 ::'>
              <a-input :readOnly='true' v-decorator="['actName', validatorRules.actName]" />
            </a-form-item>
          </a-col>
          <a-col :md='8' :sm='24'>
            <a-form-item label='活动编码 ::'>
              <a-input :readOnly='true' v-decorator="['actCode', validatorRules.actName]" />
            </a-form-item>
          </a-col>
          <a-col :md='8' :sm='24'>
            <a-form-item

              label='活动时间 ::'>
              <a-range-picker format='YYYY-MM-DD'
                              :readOnly='true'
                              v-decorator="['rangDate',validatorRules.rangDate]" />
            </a-form-item>
          </a-col>
          <a-col :md='8' :sm='24'>
            <a-form-item label='创建人 ::'>
              <a-input :readOnly='true' v-decorator="['createName', validatorRules.actName]" />
            </a-form-item>
          </a-col>
          <a-col :md='8' :sm='24'>
            <a-form-item label='创建时间 ::'>
              <a-input :readOnly='true' v-decorator="['createDate', validatorRules.actName]" />
            </a-form-item>
          </a-col>
          <a-col :md='8' :sm='24'>
            <a-form-item label='渠道类型 ::'>
              <!--              <cn-dict-select-tag :options="{value:'dictDataCode',label:'dictDataDesc'}"-->
              <!--                                 dictCode='terminal_type'-->
              <!--                                 :readOnly='true'-->
              <!--                                 v-decorator="['channelCode']" />-->
              <a-input :readOnly='true' v-decorator="['channelName']" />
            </a-form-item>
          </a-col>
          <a-col :md='8' :sm='24'>
            <a-form-item label='组织 ::'>
              <a-input :readOnly='true' v-decorator="['actOrgName', validatorRules.actName]" />
              <a-input type='hidden' :readOnly='true'
                       v-decorator="['actOrgCode', validatorRules.actName]" />
            </a-form-item>
          </a-col>
          <a-col :md='8' :sm='24'>
            <a-form-item label='参与客户 ::'>
              <a-input :readOnly='true' v-decorator="['custName', validatorRules.actName]" />
              <a-input type='hidden' :readOnly='true'
                       v-decorator="['custCode', validatorRules.actName]" />
            </a-form-item>
          </a-col>
          <a-col :md='8' :sm='24'>
            <a-form-item
              label='参与终端 ::'>
              <div style='display: flex'>
                <a-button type='primary' @click='custSearchPro2("terminaCode")'>点击查看</a-button>
              </div>
            </a-form-item>
          </a-col>

          <a-col :md='24' :sm='24' style='border-bottom: 1px solid #cdcdcd;border-top: 1px solid #cdcdcd;margin-bottom: 12px'>
            <span class='activeMess'>核销信息</span>
          </a-col>
          <a-col :md='24' :sm='24'>
            <div class='box-text'><span class='total-title'>总计核销 :<span style='margin-left:14px'>{{ totalData.money || 0 }}</span> </span></div>
          </a-col>
          <a-col :md='24' :sm='24'>
          <div class='total-box'>
            <div class='total-title'>核销示例 :</div>
            <a-button type='primary' style='width: 130px' @click='watchExample'>点击查看</a-button>
          </div>
          </a-col>
          <a-col :md='24' :sm='24'>
          <div class='total-box'>
            <div class='total-title'>执行结果 :</div>
            <a-button type='primary' style='width: 130px' @click='handleSeeDetail'>点击查看</a-button>
          </div>
          </a-col>
          <div>
            <div class='chooseActive1'>
              <div class='choose-left'>
                <a-tabs>
                  <a-tab-pane v-for='(item,i) in detailVos' :key='item.id'
                              :tab='item.categoriesDetailName'>
                    <a-card class='tab-card' v-for='(items,num) in item.infoVos' :key='num'>
                      <div style='margin-top: 10px'>
                        <a-col :md='12' :sm='24'>
                          <a-form-item

                            label='预算编码 ::'
                            >
                            <a-input placeholder='请输入预算编码'
                                     :readOnly='true'
                                     v-model='items.budgetCode'
                            />
                            <!--                            v-decorator='[items.budgetCode, validatorRules.terminalName]'-->
                          </a-form-item>
                        </a-col>
                        <a-col :md='12' :sm='24'>
                          <a-form-item
                            label='申请金额 ::'
                            >
                            <a-input placeholder='请输入申请金额' @change='e =>  moneyTotal(e,items)'
                                     :readOnly='true' v-model='items.applyAmount'
                            />
                          </a-form-item>
                        </a-col>
                        <!--                      支付方式-->
                        <a-col :md='12' :sm='24'>
                          <a-form-item

                            label='可核销金额 ::'
                            >
                            <a-input type='number' :readOnly='true' v-model='items.uableAuditAmount'
                                     placeholder='请输入金额'></a-input>
                          </a-form-item>
                        </a-col>
                        <a-col :md='12' :sm='24'>
                          <a-form-item

                            label='核销金额 ::'
                            >
                            <a-input type='number'
                                     v-model=' items.uableAuditAmount < items.auditAmount ?  items.auditAmount = items.uableAuditAmount : items.auditAmount'
                                     @change='e =>  moneyTotal(e,items,num)'
                                     :readOnly='true' placeholder='请输入金额'></a-input>
                          </a-form-item>
                        </a-col>
                        <a-col :md='12' :sm='24'>
                          <a-form-item

                            label='支付方式 ::'
                            >
                            <!--                            <cn-dict-select-tag :disabled='disableSubmit'-->
                            <!--                                               :options="{value:'dictDataCode',label:'dictDataDesc'}"-->
                            <!--                                               :triggerChange='true'-->
                            <!--                                               dictCode='pay_ways'-->
                            <!--                                               @change='e => handleInput(e,num,i,"payType")'-->
                            <!--                                               v-model='items.payType'-->
                            <!--                                               placeholder='请选择' />-->
                            <a-input  v-model='items.payTypeStr'
                                      :readOnly='true' placeholder='请选择支付方式'></a-input>
                          </a-form-item>
                        </a-col>
                        <a-col :md='12' :sm='24' v-if='items.payType == 2'>
                          <a-form-item

                            label='商品层级 ::'
                            >
                            <!--                            <j-tree-select-->
                            <!--                              :disabled='disableSubmit'-->
                            <!--                              v-model='items.hbProductLevelName'-->
                            <!--                              placeholder='请选择商品层级'-->
                            <!--                              data-type='product_type'-->
                            <!--                              @change='(e,v)=>changeJselect(e,v,i,"hbProductLevelName",num)'-->
                            <!--                            />-->
                            <a-input  :readOnly='true'  v-model='items.hbProductLevelName'></a-input>
                          </a-form-item>
                        </a-col>
                        <a-col :md='12' :sm='24' v-if='items.payType == 2'>
                          <a-form-item

                            label='货补商品 ::'
                          >
                            <a-input-search placeholder='请选择商品'
                                            v-model='items.hbProductName'
                                            readOnly enter-button
                                            @search='custSearchPro2("productName",i, items.hbProductLevelCode,num)' />
                            <a-input type='hidden' v-model='items.hbProductCode'></a-input>
                          </a-form-item>
                        </a-col>
                        <a-col :md='12' :sm='24' v-if='items.payType == 3'>
                          <a-form-item

                            label='税点 ::'
                            >
                            <a-input :disabled='disableSubmit' v-model='items.taxPoint' placeholder='请输入税点'></a-input>
                          </a-form-item>
                        </a-col>
                      </div>
                      <div>
                        <div v-if='item.categoriesDetailType == 1'>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='陈列形式 ::'
                              >
                              <j-multi-select-tag
                                v-model='item.displayForm'
                                dictCode='display_style'
                                type='select'>
                              </j-multi-select-tag>
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='陈列位置 ::'
                              >
                              <a-input placeholder='请输入陈列位置' v-model='item.displayForm' />
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='陈列商品 ::'>
                              <j-select-product v-model='item.displayProductCode' placeholder='请选择商品'
                                                :queryParams='ptQueryParam'
                                                :multiple='true' @select='(row)=>selectRole(row,i)' />
                            </a-form-item>
                          </a-col>
                        </div>
                        <!--                      人员费-->
                        <!--                      <div>-->
                        <div v-if='item.categoriesDetailType == 3'>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='人员性质 ::'
                              >
                              <j-multi-select-tag
                                v-model='item.manNature'
                                dictCode='person_point'
                                type='select'>
                              </j-multi-select-tag>
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='人数 ::'
                              >
                              <a-input type='number' :min='0' placeholder='请输入人数' v-model='item.num' />
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='日工资 ::'
                              >
                              <a-input type='number' :min='0' placeholder='请输入日工资' v-model='item.dailyWage' />
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='聘用时间 ::'
                              >
                              <a-range-picker showTime format='YYYY-MM-DD' v-model='item.employDate'
                                              @change='e=>dataChange(e,i,"employStartDate")' style='width:100%' />
                            </a-form-item>
                          </a-col>
                        </div>
                        <!--                      </div>-->
                        <!--                      样品费-->
                        <div v-if='item.categoriesDetailType == 4'>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='商品层级 ::'
                              >
                              <j-tree-select
                                v-model='item.productLevelName'
                                placeholder='请选择商品层级'
                                data-type='product_type'
                                @change='(e,v)=>changeJselect(e,v,i,"productLevelName",num)'
                              />
                              <a-input v-model='item.productLevelCode'></a-input>
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='商品 ::'
                              >
                              <a-input-search placeholder='请选择商品'
                                              :disabled=!item.productLevelCode
                                              v-model='item.productName'
                                              readOnly enter-button
                                              @search='custSearchPro2("productName",i, item.productLevelCode)' />
                              <a-input type='hidden' v-model='item.productCode'></a-input>
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='申请数量 ::'
                              >
                              <a-input type='number' :min='0' placeholder='请输入日工资' v-model='item.applyNum' />
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='寄送对象 ::'
                              >
                              <a-input placeholder='请输入寄送对象' v-model='item.sendObj' />
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                        </div>
                        <!--广宣费用-->
                        <div v-if='item.categoriesDetailType == 6'>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='刊位 ::'
                              >
                              <a-input placeholder='请输入寄送对象' v-model='item.journalPosition' />
                            </a-form-item>
                          </a-col>
                        </div>
                        <!--                      进场费-->
                        <div v-if='item.categoriesDetailType == 7'>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='门店数量 ::'
                              >
                              <a-input type='number' :min='0' placeholder='请输入门店数量' v-model='item.terminalNum' />
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='条码数量 ::'
                              >
                              <a-input type='number' :min='0' placeholder='请输入条码数量' v-model='item.barCodeNum' />
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='单条码金额 ::'
                              >
                              <a-input type='number' :min='0' placeholder='请输入单条码金额' v-model='item.singleAmount' />
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='回报周期 ::'
                              >
                              <a-input type='number' :min='0' placeholder='请输入回报周期' v-model='item.returnCycle' />
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                        </div>
                        <!--                      试吃费-->
                        <div v-if='item.categoriesDetailType == 8'>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='试吃商品 ::'
                              >
                              <a-input-search placeholder='请选择试吃商品'
                                              v-model='item.eatProductName'
                                              readOnly enter-button
                                              @search='custSearchPro("eatProductName",i)' />
                              <a-input type='hidden' v-model='item.eatProductCode'></a-input>
                            </a-form-item>
                          </a-col>
                        </div>
                        <!--                      场地费-->
                        <div v-if='item.categoriesDetailType == 11'>
                          <a-col :md='12' :sm='24'>
                            <a-form-item

                              label='活动地点 ::'
                              >
                              <a-input placeholder='请输入活动地点' v-model='item.actAddress' />
                              <!--                          @change='e => displayFormGet(e,i)'-->
                            </a-form-item>
                          </a-col>
                        </div>
                      </div>
                    </a-card>
                    <!--                      备注区域-->
                    <a-card>
                      <a-col :md='24' :sm='24'>
                        <a-form-item

                          label='说明 ::'
                          >
                          <a-textarea placeholder='请输入备注' v-model='item.remarks' />
                        </a-form-item>
                      </a-col>
                    </a-card>
                  </a-tab-pane>
                </a-tabs>
              </div>
<!--              <div class='choose-right'>-->
<!--                <div class='total-box'>-->
<!--                  <div class='total-title'>合计信息</div>-->
<!--                  <div class='box-text'><span>总计核销 : {{ totalData.money || 0 }}</span>-->
<!--                    <span>活动细类数量 : {{ totalData.number }}</span></div>-->
<!--                </div>-->

<!--                <div class='total-box'>-->
<!--                  <div class='total-title'>预算核销情况</div>-->
<!--                  <div>-->
<!--                    <a-table bordered :data-source='dataSource2' :columns='columns1' style='margin: 0 auto'>-->

<!--                    </a-table>-->
<!--                  </div>-->
<!--                </div>-->
<!--              </div>-->
            </div>
          </div>
          </a-col>
        </a-row>
      </a-form>
      <!--      <select-budget-info ref='selectBudgetInfo' @ok='getCallIn'></select-budget-info>-->
      <writeExample ref='writeExample' :unDownUrl=false :unOrDown=true @okbro='exampleOk'></writeExample>
      <feeApplyDetail ref='detailForm'></feeApplyDetail>
      <m-phone-proChose ref='prochoose' v-bind='modalProps' @okbro='okbropro'></m-phone-proChose>
      <!--      <orgtoTerminal ref='orgtoUser' @ok='saveUserRelation'></orgtoTerminal>-->
    </a-spin>
  </div>
</template>

<script>
import orgtoTerminal from '@/views/tmr/costCenter/modules/orgtoTerminal'
import JSelectProduct from '@/components/cn-select-popup/JSelectProduct'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import pick from 'lodash.pick'
import JImageUpload from '@/components/cn-form/JImageUpload'
import JTreeSelect from '@/components/cn-form/JTreeSelect'
import JSelectUserByDep from '@/components/cn-select-popup/JSelectUserByDep'
import JSelectTerminalHy from '@/components/cn-select-popup/JSelectTerminalHy'
import mPhoneProChose from './modules/mPhoneProChose'
import { queryDepartTreeList } from '@/api/api'
import { getAction, postAction, deleteAction } from '@/api/manage'
import selectBudgetInfo from '@/views/tmr/tmrComponents/selectBudgetInfo'
import HpayselectCom from '@/components/cn-components/HpayselectCom'
import writeExample from './modules/writeExample'
import feeApplyDetail from './modules/feeApplyDetail'
import moment from 'moment'

export default {
  name: 'mfeecheck',
  components: {
    feeApplyDetail,
    orgtoTerminal,
    JSelectProduct,
    JImageUpload,
    JTreeSelect,
    JSelectUserByDep,
    JSelectTerminalHy,
    mPhoneProChose,
    selectBudgetInfo,
    HpayselectCom,
    JMultiSelectTag,
    writeExample
  },
  data() {
    return {
      totalData: {},
      ptQueryParam: {},
      points: false,
      showBouns: false,
      customerList: [],
      detailVos: [],
      infoVos: [],
      templateData: {},
      dataSource1: [],
      dataSource2: [],
      custList: [],
      name: '',
      terminalName: '',
      terminalCode: '',
      title: '操作',
      visible: false,
      model: {},
      labelCol1: {
        xs: {
          span: 24
        }
        ,
        sm: {
          span: 10
        }
      },
      wrapperCol1: {
        xs: {
          span: 24
        }
        ,
        sm: {
          span: 14
        }
      },
      labelCol: {
        xs: {
          span: 24
        }
        ,
        sm: {
          span: 5
        }
      },
      wrapperCol: {
        xs: {
          span: 24
        }
        ,
        sm: {
          span: 19
        }
      },
      confirmLoading: false,
      loading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        warehouseCode: {
          rules: [{
            required: true, message: '请输入仓库编码!', trigger: 'submit'
          }]
        }
        ,
        warehouseName: {
          rules: [{
            required: true, message: '请输入仓库名称!', trigger: 'submit'
          }]
        }
        ,
        warehouseType: {
          rules: [{
            required: true, message: '请选择类型!', trigger: 'submit'
          }]
        }
        ,
        status: {
          rules: [{
            required: true, message: '请选择状态!', trigger: 'submit'
          }]
        }
      },
      url: {
        add: window._CONFIG['domianTpmURL'] + '/tpmAudit/doSaveAudit',
        applyAct: window._CONFIG['domianTpmURL'] + '/acttemplate/tpmActTemplate/findCategoriesDetailList',
        custumerList: window._CONFIG['domianURL'] + '/customerController/findCustListByOrg',
        uploadClick: window._CONFIG['domianTpmURL'] + '/tpmAuditAttachment/doUpdateAuditAttachment',
        detail: window._CONFIG['domianTpmURL'] + '/oaActivity/getAuditDetail'
      },
      treeData: [],
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          fixed: 'left',
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '可用余额',
          align: 'center',
          dataIndex: 'a',
          fixed: 'left',
          width: 120
        },
        {
          title: '预算编码',
          align: 'center',
          dataIndex: 'budgetCode'
        },
        {
          title: '预算科目',
          align: 'center',
          dataIndex: 'budgetSubjectsName'
        },
        {
          title: '预算类型',
          align: 'center',
          dataIndex: 'budgetTypeStr'
        },
        {
          title: '对象',
          align: 'center',
          dataIndex: 'budgetOrgName'
        },
        {
          title: '可用余额',
          align: 'center',
          dataIndex: 'amount'
        },
        {
          title: '年份',
          align: 'center',
          dataIndex: 'budgetYear'
        },
        {
          title: '季度',
          align: 'center',
          dataIndex: 'budgetQuarter'
        },
        {
          title: '月份',
          align: 'center',
          dataIndex: 'budgetMonth'
        },
        {
          title: '商品层级',
          align: 'center',
          dataIndex: 'productLevelName'
        },
        {
          title: '商品名称',
          align: 'center',
          dataIndex: 'productName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 100,
          scopedSlots: {
            customRender: 'action'
          }
        }
      ],
      columns1: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          fixed: 'left',
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '预算编码',
          align: 'center',
          dataIndex: 'budgetCode'
        },
        {
          title: '对象',
          align: 'center',
          dataIndex: 'budgetOrgName'
        },
        {
          title: '核销金额',
          align: 'center',
          dataIndex: 'auditAmount'
        }

      ],
      terminalData: [],
      disableSubmit: false
    }
  },
  methods: {
    handleSeeDetail() {
      this.$refs.detailForm.edit(this.model)
      this.$refs.detailForm.disableSubmit = false
    },
    exampleOk(e1, e2, e3, e4) {
      let that = this
      let param = {
        uploadVos: [...e4]
      }
      // postAction(this.url.uploadClick, param).then((res) => {
      //   if (res.success) {
      //     that.$message.success(res.message)
      //   } else {
      //     that.$message.warning(res.message)
      //   }
      // })
      // console.log('2')
    },
    watchExample(status, status2, codeKey) {
      this.$refs.writeExample.rowKey = 'exampleCode'
      // this.$refs.writeExample.isorter.auditCode = this.model.auditCode
      this.$refs.writeExample.isorter.auditCode = this.model.changeVersion
      this.$refs.writeExample.isorter.ways = 'get'
      let formconfig = [
        {
          key: 'matnr',
          label: '产品编码'
        },
        {
          key: 'maktx',
          label: '产品名称'
        }
      ]
      let tableconfig = {
        columns: [],
        list: window._CONFIG['domianTpmURL'] + '/oaActivity/getExampleList',
        multiple: false,
        columW: 11
      }
      this.proName = '细类详情'
      this.$refs.writeExample.edit(formconfig, tableconfig, status, status2)
    },
    userlist() {
      if (!this.templateData.templateCode) {
        this.$message.info('请先选择模板')
        return
      }
      if (this.model.actCode) {
        this.templateData.actCode = this.model.actCode
      } else {
        this.templateData.actCode = null
      }
      this.$refs.orgtoUser.showModal(this.templateData)
    },
    saveUserRelation(cord) {
      // let codes = cord.users.map(item => {
      //   return item.terminalName
      // })
      // this.terminalData = cord.users
      // this.form.setFieldsValue({
      //   terminals: codes
      // })
      console.log(cord)
    },
    moneyTotal(e, cord, dex) {
      let nums = cord.auditAmount - 0
      if (nums > cord.uableAuditAmount) {
        this.$message.info('核销金额不能大于可核销金额,请重新输入')

      }
      // 计算总计值
      let dataSource = this.detailVos
      let totals = 0
      let a = 0
      dataSource.forEach(item => {
        item.infoVos.forEach(itemss => {
          itemss.uableAuditAmount < itemss.auditAmount ? itemss.auditAmount = itemss.uableAuditAmount : itemss.auditAmount
          a = itemss.auditAmount ? itemss.auditAmount : 0
          totals += (a - 0)
        })
      })
      this.totalData.money = totals

      // 计算表格行内总值
      let dataSource2 = this.dataSource2
      dataSource2.forEach(item => {
        item.auditAmount = 0
        let a = 0
        dataSource.forEach(items => {
          items.infoVos.forEach(itemss => {
            if (itemss.budgetCode == item.budgetCode) {
              itemss.uableAuditAmount < itemss.auditAmount ? itemss.auditAmount = itemss.uableAuditAmount : itemss.auditAmount
              a = itemss.auditAmount ? itemss.auditAmount : 0
              item.auditAmount += (a - 0)
            }
          })

        })
      })
      this.$set(this.dataSource2, dataSource2)


    },
    handleDelect(key) {
      const dataSurces = [...this.dataSource1]
      this.dataSource1 = dataSurces.filter(item => item.id !== key)
    },
    dataChange(e1, i, key) {
      const target = this.detailVos[i]
      if (key == 'employStartDate') {
        target.employStartDate = e1[0].format('YYYY-MM-DD')
        target.employEndDate = e1[1].format('YYYY-MM-DD')
      }
      this.$set(this.detailVos, i, target)
      console.log(this.detailVos)
    },
    custSearchPro2(status, status2, codeKey, num) {
      if (status == 'terminaCode') {
        this.$refs.prochoose.rowKey = 'auditTerminalCode'
        this.$refs.prochoose.isorter.changeVersion = this.model.changeVersion
        let formconfig = [
          {
            key: 'auditTerminalCode',
            label: '终端编码'
          },
          {
            key: 'auditTerminalName',
            label: '终端名称'
          }
        ]
        let tableconfig = {
          columns: [
            {
              title: '序号',
              dataIndex: '',
              key: 'rowIndex',
              width: 60,
              align: 'center',
              customRender: function(t, r, index) {
                return parseInt(index) + 1
              }
            },
            {
              title: '终端编码',
              align: 'center',
              dataIndex: 'auditTerminalCode',
              width: 120,
              ellipsis: true
            },
            {
              title: '终端名称',
              align: 'center',
              dataIndex: 'auditTerminalName',
              width: 120,
              ellipsis: true
            }
          ],
          list: window._CONFIG['domianTpmURL'] + '/oaActivity/findPageListTerminal',
          multiple: false,
          columW: 26

        }
        this.proName = '终端'
        this.$refs.prochoose.edit(formconfig, tableconfig, status, status2)
      } else if (status == 'productName') {
        console.log(codeKey)
        this.$refs.prochoose.rowKey = 'matnr'
        this.$refs.prochoose.isorter.typeCode = codeKey
        let formconfig = [
          {
            key: 'matnr',
            label: '产品编码'
          },
          {
            key: 'maktx',
            label: '产品名称'
          }
        ]
        let tableconfig = {
          columns: [
            {
              title: '产品编码',
              align: 'center',
              dataIndex: 'matnr',
              width: 120,
              ellipsis: true
            },
            {
              title: '产品名称',
              align: 'center',
              dataIndex: 'maktx',
              width: 120,
              ellipsis: true
            }
          ],
          list: window._CONFIG['domianURL'] + '/cnProductController/getProductListByCust',
          multiple: false,
          columW: 26
        }
        this.proName = '产品'
        this.$refs.prochoose.edit(formconfig, tableconfig, status2, num)
      }
    },
    custSearchPro(status, status2) {
      this.$refs.prochoose.rowKey = 'matnr'
      let formconfig = [
        {
          key: 'matnr',
          label: '产品编码'
        },
        {
          key: 'maktx',
          label: '产品名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '产品编码',
            align: 'center',
            dataIndex: 'matnr',
            width: 120,
            ellipsis: true
          },
          {
            title: '产品名称',
            align: 'center',
            dataIndex: 'maktx',
            width: 120,
            ellipsis: true
          }
        ],

        list: window._CONFIG['domianURL'] + '/cnProductController/getProductListByCust',
        multiple: false,
        columW: 26
      }
      this.proName = '产品'
      this.$refs.prochoose.edit(formconfig, tableconfig, status, status2)
    },
    selectRole(row, status2) {
      const target = this.actDetails[status2]
      target.displayProductName = row.map(item => {
        return item.maktx
      })
      this.$set(this.actDetails, status2, target)
      console.log(this.actDetails)
    },
    changeJselect(name, value, i, key, num) {
      const dataSource = this.detailVos[i].infoVos
      const target = dataSource.find((item, index) => index == num)
      if (key == 'productLevelName') {
        target.productLevelCode = name
        target.productLevelName = value
      }
      if (key == 'hbProductLevelName') {
        target.hbProductLevelCode = name
        target.hbProductLevelName = value
        target.hbProductName = undefined
        target.hbProductCode = undefined
      }
      this.$set(this.detailVos[i], 'infoVos', dataSource)
      console.log(this.detailVos)
    },
    handleInput(e, num, i, key) {
      console.log(e, num, i, key)
      if (key == 'payType') {
        this.points = false
        this.showBouns = false
        if (e == 2) {
          this.showBouns = true
        } else if (e == 3) {
          this.points = true
        }
      }
      const dataSource = this.detailVos[i].infoVos
      const target = dataSource.find((item, index) => index == num)
      target.hbProductLevelName = undefined
      target.hbProductLevelCode = undefined
      target.hbProductName = undefined
      target.hbProductCode = undefined
      target.taxPoint = undefined
      if (target) {
        target.payType = e
      }
      this.$set(this.detailVos[i], 'infoVos', dataSource)
      console.log(this.detailVos)
    },
    // 根据组织查客户列表
    channelTypeCh(e, key) {
      if (key.dictCode == 'cust_channel') {
        this.form.setFieldsValue({
          channelCode: key.dictDataCode,
          channelName: key.dictDataDesc
        })
      }
      console.log(e, key)
    },
    // orgCodeCh(e, key) {
    //   console.log(e, key)
    //   this.form.setFieldsValue({
    //     actOrgCode: e,
    //     actOrgName: key
    //   })
    //   getAction(this.url.custumerList, { orgCode: e }).then(res => {
    //     if (res.success) {
    //       console.log(res)
    //       this.customerList = res.result
    //     } else {
    //       this.$message.warning(res.message)
    //     }
    //   })
    // },
    getPayMoney(e) {
      console.log('889')
      console.log(e)
      console.log(this.form.getFieldValue('terminals'))
      console.log('889')
    },
    personChange(e) {
      console.log(e)
    },
    loadTree() {
      var that = this
      queryDepartTreeList().then((res) => {
        if (res.success) {
          that.treeData = []
          let treeList = res.result
          for (let a = 0; a < treeList.length; a++) {
            let temp = treeList[a]
            temp.isLeaf = temp.leaf
            that.treeData.push(temp)
          }
        }
      })
    },

    modalFormOk(e1, e2) {
      console.log(e1, e2)
    },
    add() {
      this.edit({})
    },
    edit(idKey) {
      if (!idKey) {
        this.$message.info('请确认id格式是否正确')
        return
      }
      getAction(this.url.detail, { id: idKey }).then(res => {
        if (!res.success) {
          this.$message.error(res.message)
          return
        }

        let record = res.result
        this.form.resetFields()
        this.templateData = {}
        this.detailVos = []
        this.model = Object.assign({}, record)
        // this.dataSource1 = this.model.budgetCodes

        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, Object.keys(this.model)))
          this.form.setFieldsValue({ rangDate: [this.model.actStartDate, this.model.actEndDate] })
          this.detailVos = record.detailVos
          this.templateData = {
            actScopeType: this.model.actScopeType,
            templateName: this.model.templateName,
            templateCode: this.model.templateCode
          }
          this.totalData.money = this.model.auditTotalAmount
          this.totalData.number = this.model.categoriesDetailNum
          this.dataSource2 = this.model.totalList
        })
      })
    },
    close() {
      this.visible = false
    },
    okbropro(record, status, status2, status3) {
      console.log(record, status, status2, status3)
      if (status == 'customerCode') {
        this.form.setFieldsValue({
          customerCode: record[0].customerCode,
          customerName: record[0].customerName
        })
      } else if (status == 'copyV') {
        this.templateData = Object.assign({}, record[0])
        getAction(this.url.applyAct, { templateCode: this.templateData.templateCode }).then(res => {
          if (res.success) {
            // console.log(res)
            this.detailVos = []
            this.detailVos = res.result
            this.detailVos.forEach(item => {
              item.infoVos = JSON.parse(JSON.stringify(this.infoVos))
              console.log('items')
            })
            this.totalData.number = this.detailVos.length
            console.log(this.infoVos)

          } else {
            that.$message.warning(res.message)
          }
        })
      } else if (status == 'product') {
        const target = this.detailVos[status2]
        target.displayProductName = record[0].maktx
        target.displayProductCode = record[0].matnr
        this.$set(this.detailVos, status2, target)
      } else if (status == 'eatProductName') {
        const target = this.detailVos[status2]
        target.eatProductName = record[0].maktx
        target.eatProductCode = record[0].matnr
        this.$set(this.detailVos, status2, target)
      } else {
        // 支付方式添加商品
        const dataSource = this.detailVos[status].infoVos
        const target = dataSource.find((item, index) => index == status2)
        if (target) {
          target.hbProductName = record[0].maktx
          target.hbProductCode = record[0].matnr
        }
        this.$set(this.detailVos[status], 'infoVos', dataSource)
        console.log(this.detailVos)
      }
    },
    custOrgCodeSearch(status) {
      if (!this.dataSource1 || this.dataSource1.length == 0) {
        this.$message.info('请先选择预算信息')
        return
      }
      this.$refs.prochoose.rowKey = 'id'
      let formconfig = [
        {
          key: 'templateCode',
          label: '活动模版编号'
        },
        {
          key: 'templateName',
          label: '活动模版名称'
        }

      ]
      let tableconfig = {
        columns: [
          {
            title: '活动模版编号',
            align: 'left',
            width: 120,
            dataIndex: 'templateCode'
          },
          {
            title: '活动模版名称',
            align: 'left',
            dataIndex: 'templateName',
            width: 120
          },
          {
            title: '关联预算科目',
            align: 'left',
            dataIndex: 'budgetSubjectsName',
            width: 120
          }
        ],
        list: window._CONFIG['domianTpmURL'] + '/acttemplate/tpmActTemplate/findPageListActivity',
        multiple: false,
        columW: 10
      }
      this.name = '活动模板'
      this.$refs.prochoose.edit(formconfig, tableconfig, status, 'superName')
    },
    personSearch(status) {
      this.$refs.prochoose.rowKey = 'id'
      let formconfig = [
        {
          key: 'realname',
          label: '用户账户'
        },
        {
          key: 'username',
          label: '用户名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '用户账户',
            align: 'left',
            dataIndex: 'realname',
            width: 120,
            ellipsis: true
          },
          {
            title: '用户名称',
            align: 'left',
            dataIndex: 'username',
            width: 120,
            ellipsis: true
          }
        ],
        list: window._CONFIG['domianURL'] + '/cnUserController/findEnterpriseUsersPageList',
        multiple: false,
        columW: 10
      }
      this.name = '用户'
      let dataSource = []
      if (this.form.getFieldValue('username')) {
        dataSource = [{
          username: this.form.getFieldValue('username'),
          realname: this.form.getFieldValue('realname')
        }]
      }
      console.log(dataSource)
      this.$refs.prochoose.edit(formconfig, tableconfig, status, 'realname', dataSource)
    },
    custSearch(status = 'customerCode') {

      this.$refs.prochoose.rowKey = 'customerCode'
      let formconfig = [
        {
          key: 'customerCode',
          label: '经销商编码'
        },
        {
          key: 'customerName',
          label: '经销商名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '经销商编码',
            align: 'center',
            dataIndex: 'customerCode',
            width: 120,
            ellipsis: true
          },
          {
            title: '经销商名称',
            align: 'center',
            dataIndex: 'customerName',
            width: 120,
            ellipsis: true
          }
        ],
        list: window._CONFIG['domianURL'] + '/customerController/getPageList',
        multiple: false,
        columW: 11
      }
      // let dataSource = []
      // if (this.form.getFieldValue('custCode')) {
      //   dataSource = [{
      //     custCode: this.form.getFieldValue('custCode'),
      //     custName: this.form.getFieldValue('custName')
      //   }]
      // }
      this.name = '经销商'
      this.$refs.prochoose.edit(formconfig, tableconfig, status, 'status2', null)
    },
    moment,
    handleOk(status) {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let formData = Object.assign({}, this.model, this.templateData, values)
          console.log(formData)
          formData.terminals = this.terminalData
          // formData.budgetCodes = this.dataSource1.map(item => {
          //   return item.budgetCode
          // })
          formData.bpmStatus = status
          formData.detailVos = this.detailVos
          this.disableSubmit = true
          postAction(this.url.add, formData).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.disableSubmit = false
            that.close()
          })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    handlebuget() {
      // this.$refs.selectBudgetInfo.queryParam['id']=this.model.id
      this.$refs.selectBudgetInfo.url.list = window._CONFIG['domianTpmURL'] + '/budget/tpmBudgetFee/findPageList'
      this.$refs.selectBudgetInfo.multiple = true
      this.$refs.selectBudgetInfo.edit()
      this.$refs.selectBudgetInfo.edit()
      this.$refs.selectBudgetInfo.disableSubmit = false
    },
    getCallIn(e1, e2) {
      console.log(e1, e2)
      this.dataSource1 = e2
    }
  },
  created() {
    let key = location.search.replace('?id=', '')
    this.edit(key)
  },
  computed: {
    modalProps() {
      return Object.assign({}, {
        name: this.name
      })
    },
    configw() {
      return {
        title: '新增发票信息',
        width: '40%',
        config: {
          list: [
            {
              label: '客户名称',
              type: 'input',
              disabled: true,
              placeholder: '请输入路由ID',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '上账科目编码',
              type: 'input',
              placeholder: '请输入上账科目编码',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '发票编码',
              type: 'input',
              placeholder: '请输入发票编码',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '税码',
              type: 'input',
              placeholder: '请输入税码',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '发票金额',
              type: 'input',
              placeholder: '请输入发票金额(不含税)',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '发票金额',
              type: 'input',
              placeholder: '请输入发票金额(含税)',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '税金',
              type: 'input',
              placeholder: '请输入税金',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: 'ERP成本中心',
              type: 'input',
              placeholder: '请输入ERP成本中心',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '摘要',
              type: 'input',
              placeholder: '请输入摘要',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            }
          ]
        }
      }
    }
  }
}
</script>

<style lang='less' scoped>
.drawer-bootom-button {
  position: absolute;
  bottom: -8px;
  width: 100%;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  left: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
}

.basicNew {
  padding: 8px 6px 8px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid #dcdfe6;
  border-top: 1px solid #dcdfe6;
  font-size: 16px;
  font-weight: 700;
}

.basicNew1 {
  margin: 12px;
  padding: 8px 6px 8px 0;
  font-size: 16px;
  font-weight: 700;
}

.addIcon {
  margin-top: 4px;
  float: right;
  cursor: pointer;
  margin-left: 8px;
  width: 35px;
  height: 30px;
  text-align: center;
  line-height: 25px;
  background-color: #4d80be;
  color: white;
  border-radius: 50%;
  font-size: 20px;
}

.chooseActive {
  width: 100%;
  background-color: #f8f8f8;
  border-top-right-radius: 10px;
  border-top-left-radius: 10px;
  min-height: 100px;
  padding: 12px 10px;
}

.chooseActive1 {
  display: flex;
  width: 100%;
  background-color: #f8f8f8;
  border-bottom-right-radius: 10px;
  border-bottom-left-radius: 10px;
  min-height: 100px;


}

.choose-left {
  overflow: auto;
  flex: 1;
  padding-top:8px
}

.tab-card {

  width: 100%;
  min-height: 100px;
}

.total-box {
  display: flex;
  justify-content:flex-start;
  flex-direction: row;
  margin-bottom: 10px;
}

.total-title {
  margin-right:15px;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 16px;
}

.box-text {
  display: flex;
  justify-content: space-between;
}

.choose-right {
  padding: 8px;
  flex: 1;
  border-left: 1px solid;
}

.activeMess {
  font-weight: 700;
  line-height: 48px;

}

/deep/ .ant-modal-body {
  padding-top: 0 !important;
}
/deep/ .ant-form-item {
  display: flex !important;
}

/deep/ .ant-form-item-label {
  width: 40% !important;
  display: flex !important;
  align-items: center !important
}

/deep/ .ant-card-body {
  padding: 0 !important;
  text-align:left !important
}

</style>